package cc.mrbird.febs.accounting.service.impl;

import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.accounting.entity.StandardMain;
import cc.mrbird.febs.accounting.mapper.StandardMainMapper;
import cc.mrbird.febs.accounting.service.IStandardMainService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 标准主科目表 Service实现
 *
 * @author baoyinlei
 * @date 2021-11-29 16:39:31
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class StandardMainServiceImpl extends ServiceImpl<StandardMainMapper, StandardMain> implements IStandardMainService {

    private final StandardMainMapper standardMainMapper;

    @Override
    public IPage<StandardMain> findStandardMains(QueryRequest request, StandardMain standardMain) {
        LambdaQueryWrapper<StandardMain> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<StandardMain> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<StandardMain> findStandardMains(StandardMain standardMain) {
	    LambdaQueryWrapper<StandardMain> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createStandardMain(StandardMain standardMain) {
        this.save(standardMain);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateStandardMain(StandardMain standardMain) {
        this.saveOrUpdate(standardMain);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteStandardMain(StandardMain standardMain) {
        LambdaQueryWrapper<StandardMain> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    public List<StandardMain> queryStandardMains() {
        LambdaQueryWrapper<StandardMain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StandardMain::getIsDeleted, 0);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public String getCodeByName(String name) {
        return this.baseMapper.getCodeByName(name);
    }
}
